// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   Avoid.java

package jones.behavior;

import jones.SimpleRobotInterface;

// Referenced classes of package jones.behavior:
//            Behavior, Arbiter

public class Avoid
    implements Behavior
{

    private static final String NAME = "Avoid";
    private double gain = 0;
    private double speed = 0;
    private boolean isOriented = false;

    public Avoid()
    {
        gain = 100D;
        speed = 255D;
        isOriented = false;
    }

    public Avoid(double gain)
    {
        this.gain = 100D;
        speed = 255D;
        isOriented = false;
        this.gain = gain;
    }

    public void setGain(double gain)
    {
        this.gain = gain;
    }

    public double getGain()
    {
        return gain;
    }

    public void setSpeed(double speed)
    {
        this.speed = speed;
    }

    public double getSpeed()
    {
        return speed;
    }

    public String getName()
    {
        return "Avoid";
    }

    public void update(double d)
    {
    }

    public void act(Arbiter arbiter)
    {
        SimpleRobotInterface robot = (SimpleRobotInterface)arbiter.getRobotInterface(((Behavior) (this)));
        if (isOriented)
        {
            robot.setLeftWheelSpeed((int)speed);
            robot.setRightWheelSpeed((int)speed);
            isOriented = false;
            return;
        }
        if (robot.isLeftIROn())
        {
            robot.setLeftWheelSpeed((int)gain);
            robot.setRightWheelSpeed((int)(-gain));
            isOriented = true;
        } else
        if (robot.isRightIROn())
        {
            robot.setLeftWheelSpeed((int)(-gain));
            robot.setRightWheelSpeed((int)gain);
            isOriented = true;
        }
    }

    public String toString()
    {
        return "Avoid";
    }
}
